﻿
#----------------------------
# Imports

import bpy
import imp
import os
import sys

import mesh

# Need to reload while changing files during development
imp.reload(mesh)
    
#-------------------------------------

#if __name__ == "__main__" :
def run(path) :

    obj = bpy.context.active_object 
    
    filename = path + os.sep + obj.name + ".mesh.xml"
    
    run(obj, filename)
    

def run(obj, filename) :    
       
    oldmode = obj.mode
    
    # For some reason, uv-information is only available
    # in object-mode
    bpy.ops.object.mode_set(mode='OBJECT')
    
    print("Exporting mesh '" + obj.data.name + "'")    
    print("   file name: " + filename)
    
    mesh.write(obj, filename)

    # obj.data.update(calc_tessface=True)
    
    #mesh.create_vertex_clones(obj.data, obj.data.uv_layers[0])

    # Reset the mode
    bpy.ops.object.mode_set(mode=oldmode)
    
    print("    Done")

